package com.dz.controller.manager;

import com.dz.annotation.OperationLog;
import com.dz.bean.Transaction;
import com.dz.bean.dto.TransactionGuideRankDTO;
import com.dz.bean.dto.TransactionTrendDTO;
import com.dz.bean.dto.TransactionVisitorDistributionDTO;
import com.dz.service.TransactionService;
import com.dz.util.Page;
import com.dz.util.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@CrossOrigin
@RequestMapping("/manager/transaction")
public class TransactionManagerController {
    @Autowired
    TransactionService transactionService;

    @GetMapping("page")
    public Result page(Page page, Transaction transaction) {
        transactionService.page(page, transaction);
        return Result.success(page);
    }

    @DeleteMapping("/{id}")
    @OperationLog("删除交易信息")
    public Result delete(@PathVariable("id") Integer id){
        int result = transactionService.delete(id);
        return Result.success(result);
    }

    /**
     * 获取交易趋势数据
     */
    @GetMapping("/trend")
    public Result getTransactionTrendData(@RequestParam(defaultValue = "7") Integer days) {
        List<TransactionTrendDTO> data = transactionService.getTransactionTrendData(days);
        return Result.success(data);
    }

    /**
     * 获取地陪收入排行数据
     */
    @GetMapping("/guide-rank")
    public Result getGuideRankData() {
        List<TransactionGuideRankDTO> data = transactionService.getGuideRankData();
        return Result.success(data);
    }

    /**
     * 获取游客消费分布数据
     */
    @GetMapping("/visitor-distribution")
    public Result getVisitorDistributionData() {
        try {
            List<TransactionVisitorDistributionDTO> data = transactionService.getVisitorDistributionData();
            return Result.success(data);
        } catch (Exception e) {
            log.error("获取游客消费分布数据失败: " + e.getMessage());
            return Result.error(500, "获取游客消费分布数据失败: " + e.getMessage());
        }
    }
}
